package com.nirvana.flatbuffers;


/**
 * Copyright (c) 2022 Aoshu.Co.Ltd. All rights reserved.
 *
 * @author :    zhouqichun
 * @create :    2025/11/14 10:13
 * @description :
 **/
public class TimeSpaceResolver implements IResolve {
    @Override
    public boolean canResolve(String propertyType) {
        return "TimeSpace".equals(propertyType);
    }

    @Override
    public String resolve(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                    val %sOffset = TimeSpaceFb.createTimeSpaceFb(builder, m.%s.startHour, m.%s.startMinute, m.%s.endHour, m.%s.endMinute)
                    """.formatted(
                propertyName,
                propertyName,
                propertyName,
                propertyName,
                propertyName
        ));
        return "%sOffset".formatted(propertyName);
    }

    @Override
    public String resolveVector(StringBuilder objectPreContent, String defName, String propertyName, String propertyType) {
        objectPreContent.append("""
                                val %sOffsets = m.%s.map(p => {
                                    TimeSpaceFb.createTimeSpaceFb(p.startHour, p.startMinute, p.endHour, p.endMinute)
                                })
                """.formatted(
                propertyName,
                propertyName
        ));
        return "%sOffsets".formatted(propertyName);
    }
}
